//
//  WebViewViewController.swift
//  FM
//
//  Created by x on 2017/9/5.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class WebViewViewController: UIViewController {
    
    /// 保存网页跳转URL
    var webURL:URL?

    init(url:URL) {
        webURL = url
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.white
        
        //添加一个webView
        let requeset = URLRequest(url: webURL!)
        webView.loadRequest(requeset)
        view.addSubview(webView)
        view.addSubview(outBtu)
    }
    
    /// 退出按钮的点击事件
    func signOutBtuClick() -> Void {
        navigationController?.popViewController(animated: true)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(true, animated: false)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.setNavigationBarHidden(false, animated: false)
    }
    
    //MARK: -- 懒加载
    private lazy var webView:UIWebView = UIWebView(frame: self.view.bounds)
    
    private lazy var outBtu:UIButton = {
        let btu = UIButton()
        btu.frame = CGRect.init(x: self.view.bounds.width-40, y: self.view.bounds.height-140, width: 40, height: 40)
        btu.backgroundColor = UIColor.orange
        btu.layer.cornerRadius = 20
        btu.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        btu.setTitle("退出", for: UIControlState.normal)
        btu.addTarget(self, action: #selector(signOutBtuClick), for: UIControlEvents.touchUpInside)
        
        return btu
    }()
}
